// "abcabcbb"  => abc
// 滑动窗口 start, end 指针
function find(str: string): number {
  let strLen = str.length
  if (strLen < 2) {
    return strLen
  }
  let start = 0
  let end = 0
  let max = 0
  let cache = new Map()
  while (end < strLen) {
    let endIndex = cache.get(str[end])
    if (endIndex == null) { // 第一次出现
      let newMax = end - start + 1
      max = newMax > max ? newMax : max
    } else { // 最近一次出现过
      start = endIndex + 1
    }
    cache.set(str[end], end)
    end++
  }
  return max
}



console.log(find("aaaaaaaa"))
console.log(find("abcabcbb"))
console.log(find("pwwkew"))